package com.difsonapps.android.marker.adapters;

import com.difsonapps.android.marker.FeedImageView;
import com.difsonapps.android.marker.R;
import com.difsonapps.android.marker.app.AppController;
import com.difsonapps.android.marker.beans.Like;
 
import java.util.List;
 
import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
 
public class LikesListAdapter extends BaseAdapter {  
    private Activity activity;
    private LayoutInflater inflater;
    private List<Like> likes;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
 
    public LikesListAdapter(Activity activity, List<Like> likes) {
        this.activity = activity;
        this.likes = likes;
    }
 
    @Override
    public int getCount() {
        return likes.size();
    }
 
    @Override
    public Object getItem(int location) {
        return likes.get(location);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
 
        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.like_item, null);
 
        if (imageLoader == null)
            imageLoader = AppController.getInstance().getImageLoader();
 
        //TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);
        NetworkImageView userImage = (NetworkImageView) convertView.findViewById(R.id.userImage);
        ImageView likeValueImageView = (ImageView) convertView.findViewById(R.id.likeValueImageView);
 
        TextView userName = (TextView) convertView.findViewById(R.id.userName);
        TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);
        Like item = likes.get(position);
        timestamp.setText(item.getRelativeDate());
        if(item.getUser()!=null) {
        	userImage.setImageUrl(item.getUser().getPictureUrl(), imageLoader);
        	userName.setText(item.getUser().getName());
        }
 		
        return convertView;
    }
 
}
